<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      function cacl(ope) {
        var inputNum1 = document.getElementById('num1').value
        var inputNum2 = document.getElementById('num2').value
        console.log('num1:' + inputNum1 + ',num2:' + inputNum2)
        if (ope === '+') {
          document.getElementById('rs').value =
            parseInt(inputNum1) + parseInt(inputNum2)
        } else if (ope === '-') {
          document.getElementById('rs').value = inputNum1 - inputNum2
        } else if (ope === '*') {
          document.getElementById('rs').value = inputNum1 * inputNum2
        } else if (ope === '/') {
          document.getElementById('rs').value = inputNum1 / inputNum2
        }
      }
    </script>
  </head>
  <body>
    <h1>计算器2</h1>
    <!-- 拷贝当前行 shift+alt+下 -->
    <input type="number" id="num1" placeholder="请输入第一个数" /> <br />
    <input type="number" id="num2" placeholder="请输入第二个数" /> <br />
    <input type="button" value="+" onclick="cacl('+')" />
    <input type="button" value="-" onclick="cacl('-')" />
    <input type="button" value="*" onclick="cacl('*')" />
    <input type="button" value="/" onclick="cacl('/')" /> <br />
    <input type="number" id="rs" placeholder="计算结果" disabled /> <br />
  </body>
</html>
